package cn.tsinghua.comsmacitccntsinghua.model;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.bgabanner.BGABanner;
import cn.tsinghua.comsmacitccntsinghua.R;
import cn.tsinghua.comsmacitccntsinghua.bean.BaseDataInfo;

/**
 * 封面广告轮播图控制类
 */
public class CoverControl {
    private Context mContext;
    private BGABanner banner;

    public CoverControl(Context mContext, BGABanner banner) {
        this.mContext = mContext;
        this.banner = banner;
        setAdapter(mContext);
    }
    //设置轮播图适配器
    public void setAdapter(final Context context){
        banner.setAdapter(new BGABanner.Adapter<ImageView, String>() {
            @Override
            public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
                Glide.with(context)
                        .load(model)
                        .placeholder(R.drawable.holder)
                        .error(R.drawable.holder)
                        .centerCrop()
                        .dontAnimate()
                        .into(itemView);
            }
        });
    }
    //设置轮播图数据
    //public void setData(List arUrl,List arTip){
    public void setData(List<BaseDataInfo.DataBean.CoverBean> data){
        List urlList = new ArrayList();//轮播图链接
        List tipList = new ArrayList();//轮播图标题  可以不用
        for (int k=0;k<data.size();k++){
            urlList.add(data.get(k).getCoverUrl());
        }
        banner.setData(urlList,tipList);
    }
    //轮播图点击事件处理
    public void onClickListener(){
        banner.setDelegate(new BGABanner.Delegate<ImageView, String>() {
            @Override
            public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {
                //TODO 点击事件处理

            }
        });
    }
}
